package com.xnfh.common.utils


import android.content.Context
import android.graphics.Bitmap
import android.net.Uri
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions.withCrossFade
import com.huantansheng.easyphotos.engine.ImageEngine

/**
 * @Description:
 * @Author: ziheng
 * @CreateDate: 2023/11/24 13:20
 * @UpdateUser: ziheng
 * @UpdateDate: 2023/11/24 13:20
 * @UpdateRemark: 更新说明
 */
class GlideEngine private constructor():ImageEngine {


    companion object {
        private var instance: GlideEngine? = null
            get() {
                if (field == null) {
                    field = GlideEngine()
                }
                return field
            }

        @Synchronized
        fun get(): GlideEngine {
            return instance!!
        }
    }

    override fun loadPhoto(context: Context, uri: Uri, imageView: ImageView) {

        Glide.with(context).load(uri).transition(withCrossFade()).into(imageView)

    }
    override fun loadGifAsBitmap(context: Context, gifUri: Uri, imageView: ImageView) {
        Glide.with(context).asBitmap().load(gifUri).into(imageView)
    }

    override fun loadGif(context: Context, gifUri: Uri, imageView: ImageView) {
        Glide.with(context).asGif().load(gifUri).transition(withCrossFade()).into(imageView)
    }

    override fun getCacheBitmap(context: Context, uri: Uri, width: Int, height: Int): Bitmap {
        return Glide.with(context).asBitmap().load(uri).submit(width, height).get()
    }
}